package com.bosssoft.ecds.controller;

/**
 * @author 张东海
 * @date 2020/8/10
 * @description 单位票据信息Controller，提供了基本的增删改查功能
 *               同时攥写了与其它小组对接了开票与票据销毁两项业务的接口
 */

import com.bosssoft.ecds.common.response.CommonCode;
import com.bosssoft.ecds.common.response.QueryResponseResult;
import com.bosssoft.ecds.common.response.ResponseResult;
import com.bosssoft.ecds.entity.dto.DestroyDTO;
import com.bosssoft.ecds.entity.dto.UabAgenBillDTO;
import com.bosssoft.ecds.entity.po.UabAgenBillPO;
import com.bosssoft.ecds.service.impl.UabAgenBillServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;

@Slf4j
@RestController
public class UabAgenBillController {

    @Resource
    UabAgenBillServiceImpl fabAgenBillService;

    @GetMapping("fabAgenBill")
    public UabAgenBillPO getById(BigInteger id){
        return fabAgenBillService.getByPrimaryKey(id);
    }

    @GetMapping("fabAgenBill/getAll")
    public QueryResponseResult getAll(){
        List<UabAgenBillPO> billList = fabAgenBillService.getAll();
        return new QueryResponseResult(CommonCode.SUCCESS,billList);
    }

    @PostMapping("fabAgenBill")
    public ResponseResult create(@RequestBody UabAgenBillPO fabAgenBill){
        int insert = fabAgenBillService.insert(fabAgenBill);
        if(insert > 0){
            return ResponseResult.SUCCESS();
        }
        return ResponseResult.FAIL();
    }

    @PutMapping("fabAgenBill")
    public ResponseResult update(@RequestBody UabAgenBillPO fabAgenBill){
        fabAgenBillService.update(fabAgenBill);
        return ResponseResult.SUCCESS();
    }

    @DeleteMapping("fabAgenBill")
    public ResponseResult delete(BigInteger id){
        fabAgenBillService.delete(id);
        return ResponseResult.SUCCESS();
    }

    @GetMapping("testKai")
    public QueryResponseResult testKai(){
        UabAgenBillDTO billDto = fabAgenBillService.kai();
        return new QueryResponseResult(CommonCode.SUCCESS,billDto);
    }

    @PostMapping("destroyStockBill")
    public int destroyStockBill(@RequestBody DestroyDTO destroyDto){
        return fabAgenBillService.destroyStockBill(destroyDto);
    }

}
